package model.workerwithfile;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;

import org.apache.log4j.Logger;

import entities.DataBase;
import autoproperties.AutoProperties;

public class ReaderFromFile {
	
	private static FileInputStream file;
	private static ObjectInputStream input;
	private static final String NOT_FOUND_FILE="Sorry, specified file or class not found.";
	private static AutoProperties auto_properties=AutoProperties.getInstance();
	private static Logger log= Logger.getLogger(ReaderFromFile.class);
	
	public static DataBase getDBFromFile() {
		try{
		DataBase db;
		file = new FileInputStream(new File(auto_properties.getFilePath()));
		input=new ObjectInputStream(file);
		 db=(DataBase) input.readObject();
		 input.close();
		 file.close();
		return db;
		}catch(Exception e){
			log.error(NOT_FOUND_FILE);
			throw new RuntimeException(NOT_FOUND_FILE);
			/*db=DataBase.getInstance();
			return db;*/
		}
		
		
	}

}
